/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.nell;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 *
 * @author Administrator
 */
public class Settings extends Activity {

    private TextView spt;
    private EditText spe;
    private final Settings settings = this;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.settings);

        //record clicks
        //record urls
        //record screenshots
        //reset database
        //path to screenshots

        CheckBox cb = (CheckBox) findViewById(R.id.record_click_check);
        cb.setChecked(ApplicationSettings.isRecordClick());
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                ApplicationSettings.setRecordClick(isChecked);
                Toast.makeText(getBaseContext(), "setting saved",
                        Toast.LENGTH_SHORT).show();
            }
        });


        cb = (CheckBox) findViewById(R.id.record_page_check);
        cb.setChecked(ApplicationSettings.isRecordPage());
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                ApplicationSettings.setRecordPage(isChecked);
                Toast.makeText(getBaseContext(), "setting saved",
                        Toast.LENGTH_SHORT).show();
            }
        });

        cb = (CheckBox) findViewById(R.id.record_screen_check);
        cb.setChecked(ApplicationSettings.isRecordScreen());
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                ApplicationSettings.setRecordScreen(isChecked);
                Toast.makeText(getBaseContext(), "setting saved",
                        Toast.LENGTH_SHORT).show();
            }
        });

        spt = (TextView) findViewById(R.id.screenshot_path_edit);
        spt.setText(ApplicationSettings.getScreenshotPath());
    }

    public void resetDB(View view) {
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.reset_db_really_title).setMessage(R.string.reset_db_really).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ApplicationSettings.dbh.recreateAllTables(ApplicationSettings.db);
                Toast toast = Toast.makeText(getBaseContext(), R.string.reset_db_complete, Toast.LENGTH_SHORT);
                toast.show();
            }
        }).setNegativeButton(R.string.no, null).show();
    }

    public void editScreenpath(View view) {
        final EditText input = new EditText(settings);
        input.setText(ApplicationSettings.getScreenshotPath());
        new AlertDialog.Builder(settings).setTitle("Screenshots").setMessage("Please edit path to screenshots").setView(input).setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                ApplicationSettings.setScreenshotPath(input.getText().toString());
                spt.setText(input.getText().toString());
            }
        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                // Do nothing.
            }
        }).show();
    }
}
